package com.etoak.service.impl;

import com.etoak.common.vo.AreaVO;
import com.etoak.entity.Area;
import com.etoak.mapper.AreaMapper;
import com.etoak.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AreaServiceImpl implements AreaService {

    @Autowired
    AreaMapper areaMapper;

    @Override
    public List<AreaVO> queryArea() {
        List<AreaVO> areaList = areaMapper.queryArea();
        return areaList;
    }

    @Override
    public void setChildren(AreaVO t, List<AreaVO> areaVOS) {
        List<AreaVO> childs = new ArrayList<>();
        for (AreaVO m:areaVOS){
            if (m.getPid()==t.getId()){
                childs.add(m);
            }
        }
        t.setDestinations(childs);
        //给子菜单 设置 子菜单
        if (childs.size()>0){
            for (AreaVO m:childs){
                //递归调用此方法
                this.setChildren(m,areaVOS);

            }
        }
    }

    @Override
    public List<AreaVO> queryByPid(int pid) {
        return areaMapper.queryByPid(pid);
    }
}
